#coding=utf-8
from django import template
import re                       # regular expressions
from decimal import Decimal

register = template.Library()

@register.simple_tag
def active (path, pattern):
    if re.search (pattern, path):
        return 'active'
    return ''

@register.simple_tag
def begin_backto ():
    return '<div id=\"back\">\n<h2>Wróć do:</h2>\n<ul>'

@register.simple_tag
def end_backto ():
    return '</ul>\n</div>'

@register.filter
def MB (nr):
    one_MB = 1000000
    nr = Decimal(nr) / Decimal(one_MB)
    
    return "%.3f" % nr 

@register.filter
def kB (nr):
    one_kB = 1000
    nr = Decimal(nr) / Decimal(one_kB)
    
    return "%.1f" % nr 
